package com.jxnu.project_z_android.navigation_demo.ui.detail;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jxnu.project_z_android.R;
import com.jxnu.project_z_android.databinding.DetailFragmentBinding;

public class DetailFragment extends Fragment {

    private DetailViewModel mViewModel;
    private DetailFragmentBinding detailFragmentBinding;

    public static DetailFragment newInstance() {
        return new DetailFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        detailFragmentBinding = DataBindingUtil.inflate(inflater, R.layout.detail_fragment, container, false);
//        return inflater.inflate(R.layout.detail_fragment, container, false);
        return detailFragmentBinding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(DetailViewModel.class);
        // TODO: Use the ViewModel
        detailFragmentBinding.btDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController controller = Navigation.findNavController(v);
                controller.navigate(R.id.action_detailFragment_to_homeFragment);
            }
        });
    }

}
